export default{
  namespaced:true,
  
  state:()=>({
    //收货地址
    address:JSON.parse(uni.getStorageSync('address')||'{}'),
    //登录成功之后的token字符串
    token:uni.getStorageSync('token')||'',
    //用户基本信息
    userInfo:JSON.parse(uni.getStorageSync('userInfo')||'{}'),
    //重定向的object对象 {openType,from}
    redirectInfo:null
  }),
  
  mutations:{
    //更新收货地址
    UPDATEADDRESS(state,address){
      state.address=address
      //持久化存储
      this.commit('user/SAVEADDRESSTOSTORAGE')
    },
    // 定义 address 持久化存储到本地
    SAVEADDRESSTOSTORAGE(state){
      uni.setStorageSync('address',JSON.stringify(state.address))
    },
    //更新用户的基本信息
    UPDATEUSERINFO(state , userInfo){
      state.userInfo = userInfo
      this.commit('user/SAVEUSERINFOTOSTORAGE')
    },
    //本地持久化存储 userInfo 
    SAVEUSERINFOTOSTORAGE(state){
      uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
    },
    //更新 token字符串
    UPDATETOKEN(state , token){
      state.token = token
      //本地持久化存储 token
      this.commit('user/SAVETOKENTOSTORAGE')  
    },
    //本地持久化存储 token
    SAVETOKENTOSTORAGE(state){
      /*  --------------- 接口有问题  先自己写好定义的token存储起来 ----------------*/
      uni.setStorageSync('token',state.token)
    },
    //更新重定向对象
    UPDATEREDIRECTINFO(state,info){
      state.redirectInfo = info
    }
  },
  
  actions:{},
  
  getters:{
    //详细收货地址
    detailAddress(state){
       if (!state.address.provinceName) return ''
       //拼接 地址
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}